import 'package:baseProjectFlutter/page/view/root_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../page/view/home_page.dart';
import '../page/view/login_page.dart';

/// 路由key
class AppRouteKey {
  static const String root = '/';
  static const String home = '/home';
  static const String login = '/login';
  static const String unknown = '/404';
}

/// 路由跳转
class AppRouterJump {
  AppRouterJump._();

  //返回
  static void back() {
    Get.back();
  }

  static void login() {
    // Navigator.push(
    //   AppRoutes.currentContext,
    //   MaterialPageRoute(builder: (context) => LoginPage()),
    // );
    //使用Push 前面页面不会销毁
    //使用Go  前面页面会销毁
    // AppRoutes.currentContext?.pushNamed(AppRouteKey.login);
    Get.toNamed(AppRouteKey.login);
  }
}

class AppRoutes {
  //全局导航key，不用BuildContext
  static final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

  static BuildContext? get currentContext => navigatorKey.currentContext;
  static final routes = [
    GetPage(
      name: AppRouteKey.root,
      page: () => RootPage(),
    ),
    GetPage(
      name: AppRouteKey.home,
      page: () => const HomePage(),
    ),
    GetPage(
      name: AppRouteKey.login,
      page: () => const LoginPage(),
    ),
  ];

  static void init() {}
}
